package com.haifeng.questionbankcrud.services.impl;

import com.haifeng.questionbankcrud.dao.TeacherDao;
import com.haifeng.questionbankcrud.dao.impl.TeacherDaoImpl;
import com.haifeng.questionbankcrud.pojo.Teacher;
import com.haifeng.questionbankcrud.pojo.vo.MessageModel;
import com.haifeng.questionbankcrud.services.LoginService;

import java.util.List;

public class LoginServiceImpl implements LoginService {
     TeacherDao dao=new TeacherDaoImpl();
    // 把controller层封装的对象和数据库查询到的对象做比较，如果一致返回1，不一致返回0
    @Override
    public int teacherLogin(Teacher teacher) {

        //查询数据库
        List<Teacher> teachers = dao.queryUserByNameAndPassword(teacher);
        //判断返回的list里是否有值，
        //有则返回1
        //消息模型对象设置为1
        //没有返回0
        //消息模型对象返回0
        if (teachers.isEmpty()) {
            //为空 未查询到数据
            return 0;
        } else {
            return 1;
        }
    }

    @Override
    public int teacherSignUp(Teacher teacher) {
        System.out.println(dao);
        return dao.addTeacher(teacher);
    }
}
